package com.mtolstykh.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Utils
{

    public static String md5sum(String s){
        MessageDigest m = null;
        try{
            m = MessageDigest.getInstance(GlobalScope.ALG_MD5);
        }
        catch (NoSuchAlgorithmException e)
        {
            e.printStackTrace();
        }
        m.reset();
        m.update(s.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        String hashtext = bigInt.toString(16);
        // Now we need to zero pad it if you actually want the full 32 chars.
        while (hashtext.length() < 32){
            hashtext = "0" + hashtext;
        }
        return hashtext;
    }

    public static long bytesToLong(byte[] value){
    	String lvalue = "0";
    	System.out.println(value.length);
    	for(int i=0;i<8;i++){
    		lvalue += String.valueOf((int)value[value.length - i]) + lvalue;
    	}
    	return Long.parseLong(lvalue);
    }

	public static String userName() {
		return System.getProperty("user.name");
	}
}
